﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace QuantumEngine
{
    
    public partial class CoolButton : Button
    {
 


        [Description("NormalState"), Category("QButton"), Browsable(true)]
        public Image StateNormal { get; set; }
        [Description("HoverState"), Category("QButton"), Browsable(true)]
        public Image StateHover { get; set; }
        [Description("ActiveState"), Category("QButton"), Browsable(true)]
        public Image StateActive { get; set; }
        [Description("Text"), Category("QButton"), Browsable(true)]
        public string CoolText { get; set; }

        private bool MouseOver = false, MousePress = false;

        public Image GetImage(string name)
        {
            System.Reflection.Assembly thisExe;
            thisExe = System.Reflection.Assembly.GetExecutingAssembly();
            System.IO.Stream file =
                thisExe.GetManifestResourceStream("QuantumEngine.Resource."+name);
            if (file == null)
            {
                return null;
            }
            return Image.FromStream(file);
        }


        public CoolButton()
        {
            InitializeComponent();
            
            StateNormal = GetImage("ButtonNormal.png");
            StateHover = GetImage("ButtonHover.png");
            StateActive = GetImage("ButtonActive.png");

   //         this.CanRaiseEvents = false;
     //       this.CanSelect = false;
       //     this.Capture = false;
           
        }

        private void qButton1_MouseDown(object sender, MouseEventArgs e)
        {
     
        }

        private void qButton1_MouseUp(object sender, MouseEventArgs e)
        {
           
        }

        private void qButton1_MouseEnter(object sender, EventArgs e)
        {
            

        }

        private void qButton1_MouseLeave(object sender, EventArgs e)
        {
    
        }

        private void qButton1_Click(object sender, EventArgs e)
        {
           
        }

        private void CoolButton_Paint(object sender, PaintEventArgs e)
        {
            if (StateNormal == null)
            {
                e.Graphics.DrawString("No data!", SystemFonts.DefaultFont, Brushes.Black, new PointF(5, 5));
                return;
            }
            var g = e.Graphics;

            Image img = null;

            if (MousePress)
            {
                img = StateActive;
            }
            else if (MouseOver)
            {
                img = StateHover;
            }
            else
            {
                img = StateNormal;
            }
            g.DrawImage(img, new Rectangle(0, 0, ClientRectangle.Width, ClientRectangle.Height));
            Brush tmpBrush = Brushes.BlanchedAlmond;
            var ts = g.MeasureString(CoolText, SystemFonts.DialogFont);
            var txtPos = new PointF(ClientRectangle.Width / 2.0f - ts.Width / 2.0f, ClientRectangle.Height / 2.0f - ts.Height / 2.0f);
            g.DrawString(CoolText, SystemFonts.DialogFont, tmpBrush, txtPos);
   
        }

        private void CoolButton_MouseEnter(object sender, EventArgs e)
        {
            MouseOver = true; this.Invalidate();
        }

        private void CoolButton_MouseLeave(object sender, EventArgs e)
        {
            MouseOver = false; this.Invalidate();
        }

        private void CoolButton_MouseDown(object sender, MouseEventArgs e)
        {
            MousePress = true; this.Invalidate();
        }

        private void CoolButton_MouseUp(object sender, MouseEventArgs e)
        {
            MousePress = false; this.Invalidate();
        }
    }
}
